﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lswweb.IDAL;
using Lswweb.Model;
using Lswweb.Domain;

namespace Lswweb.Domain
{
    public class Newsletter
    {
        #region static methods

        private static INewsletterDAL dal = DALFactory.CreateNewsletterDAL();

        public static NewsletterInfo FindById(int id)
        {
            if (id <= 0)
                return null;

            return dal.FindById(id);
        }

        public static IList<NewsletterInfo> FindAll(int pageIndex, int pageSize, out int totalRecord)
        {
            return dal.FindAll(pageIndex,pageSize,out totalRecord);
        }

        public static void Insert(NewsletterInfo info)
        {
            if (info == null)
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
                return;
            }

            try
            {
                dal.Add(info);
                SiteContext.RenderMessage(ExceptionType.HandleSuccess);
            }
            catch
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);

            }
        }

        public static void Update(NewsletterInfo info)
        {
            if (info == null)
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
                return;
            }

            try
            {
                dal.Update(info);
                SiteContext.RenderMessage(ExceptionType.HandleSuccess);
            }
            catch
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);

            }
        }

        public static void Delete(int id)
        {
            if (id <= 0)
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
                return;
            }

            try
            {
                dal.Delete(id);
                SiteContext.RenderMessage(ExceptionType.HandleSuccess);
            }
            catch
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
            }
        }

        #endregion
    }
}
